package com.leoman.barrage.dao;

import com.leoman.barrage.entity.Barrage;
import com.leoman.common.dao.IBaseJpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by Administrator on 2016/6/12.
 */
public interface BarrageDao extends IBaseJpaRepository<Barrage> {

    @Query("select a from Barrage a where a.workId = ?1 and a.type = ?2")
    public List<Barrage> iFindList(Long workId, Integer type);

    @Query("select a from Barrage a where a.workId = ?1 and a.type = ?2 and a.userInfo.isCreator = ?3")
    public List<Barrage> iFindList(Long workId, Integer type, Integer isCreator);

    @Query("select a from Barrage a where a.workId = ?1 and a.type = ?2 and a.timePlus = ?3")
    public List<Barrage> iFindList2(Long workId, Integer type, Integer timePlus);

    @Query("select a from Barrage a where a.workId = ?1 and a.userInfo.isCreator = ?2")
    public List<Barrage> iFindList3(Long workId, Integer isCreator);

    @Query("select a from Barrage a where a.createDate > ?1 and a.type = ?2")
    public List<Barrage> findListNew(Long oldDate, Integer type);

    // 用户当天发送弹幕数量
    @Query("SELECT COUNT(a) FROM Barrage a WHERE a.userInfo.id = ?1 AND a.createDate >= ?2 AND a.createDate <?3")
    public Integer findTodayBarrageNum(Long userId, Long morningDate, Long nightDate);

    @Query("select a from Barrage a where a.workId = ?1 and a.timePlus = ?2")
    public List<Barrage> findByWorkIdAndTimePlus(Long workId, Integer timePlus);
}
